package com.srwl.mytx.fragment;

import android.app.Dialog;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;

import androidx.fragment.app.DialogFragment;

import com.srwl.mytx.R;
import com.srwl.mytx.domain.Contact;


public class PrivacyPolicyDialog_v1 extends DialogFragment {



    public PrivacyPolicyDialog_v1() {
        // Required empty public constructor
    }


    public static PrivacyPolicyDialog_v1 newInstance() {
        PrivacyPolicyDialog_v1 fragment = new PrivacyPolicyDialog_v1();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //设置dialog 样式,没有标题，宽度为 android alterDialog的默认显示宽度，
        setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Holo_Light_Dialog_MinWidth);


    }


    @Override
    public void onStart() {
        super.onStart();
        Window win = getDialog().getWindow(); // 一定要设置Background，如果不设置，window属性设置无效
        // win.setBackgroundDrawable(new ColorDrawable(new ColorDrawable(Color.WHITE)));
        DisplayMetrics dm = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
        WindowManager.LayoutParams params = win.getAttributes();
       // params.gravity = Gravity.BOTTOM; // 使用ViewGroup.LayoutParams，以便Dialog 宽度充满整个屏幕
        // params.width = (int) (dm.widthPixels - 20 * dm.density);
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        params.width = ViewGroup.LayoutParams.MATCH_PARENT;
        win.setAttributes(params);
    }

//    @NonNull
    //@Override
//    public Dialog onCreateDialog(Bundle savedInstanceState) {
//        Dialog dialog = new Dialog(getActivity());
//        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // must be called before set content
//        dialog.setContentView(R.layout.authority_agreement);
//       // dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.BLACK));
//        dialog.setCanceledOnTouchOutside(true);
//
//        // 设置宽度为屏宽、在屏幕中的位置
//        Window window = dialog.getWindow();
//        // window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE| WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
//        WindowManager.LayoutParams wlp = window.getAttributes();
//        wlp.gravity = Gravity.CENTER;
//        //设置全屏
//        //wlp.width = WindowManager.LayoutParams.MATCH_PARENT;
//        wlp.height = WindowManager.LayoutParams.WRAP_CONTENT;
//        float widthPixels= getContext().getResources().getDisplayMetrics().widthPixels;
//        //按屏幕宽度，设置固定的比例
//        wlp.width= (int) (widthPixels*0.8);
//        window.setAttributes(wlp);
//        return dialog;
//    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.authority_agreement, container, false);
        TextView tvContent = view.findViewById(R.id.tv_content);
        String[] stringArray = getActivity().getResources().getStringArray(R.array.authority_agreement);
        StringBuilder agreement = new StringBuilder();
        agreement.append("    ");
        for (String s : stringArray) {
            agreement.append(s).append("\n    ");
        }
        tvContent.setText(agreement.toString());
        return view;
    }



    public void setInteractionListener(OnFragmentInteractionListener listener) {
        //mListener = listener;
    }

    public interface OnFragmentInteractionListener {

        void onSetAuthorityComplete(Contact contact);
    }
}
